<template>
  <div class="total-box">
    <!-- 搜索 -->
    <div class="section1">
      <div class="section1-1">
        <i class="el-icon-search" @click="sousuo"></i>
        <input
          type="text"
          placeholder="请输入用户名查询"
          v-model="filterText"
          class="input1"
          @input="textNone1($event)"
          @keyup.enter="textNone($event)"
        />
      </div>
    </div>
    <!-- 表格数据 -->
    <div class="table-content">
      <el-table :data="tableData" border>
        <el-table-column prop="user_id" label="用户编号"></el-table-column>
        <el-table-column prop="user_name" label="微信用户名"></el-table-column>
        <el-table-column
          prop="safetyInfo.account_money"
          label="账户余额"
        ></el-table-column>
        <el-table-column
          prop="safetyInfo.alipay_account"
          label="支付宝账号"
        ></el-table-column>
        <el-table-column
          prop="safetyInfo.withdraw_money"
          label="提现总金额"
        ></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-dropdown>
              <span class="el-dropdown-link">
                <i class="el-icon-arrow-down el-icon--right"></i>
              </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item @click.native="modify(scope.row)"
                  >编辑</el-dropdown-item
                >
              </el-dropdown-menu>
            </el-dropdown>
          </template>
        </el-table-column>
      </el-table>

      <el-dialog
        title="用户安全信息"
        :visible.sync="dialogFormVisible"
        width="600px"
      >
        <el-form :model="form">
          <!-- 头像 -->
          <div class="touxiangdiv">
            <div class="touxiang">
              <img v-if="imageUrl" :src="imageUrl" class="avatar" />
            </div>
          </div>
          <el-form-item
            label="用户编号"
            :label-width="formLabelWidth"
            class="from-item"
          >
            <el-input
              :value="form.user_id"
              autocomplete="off"
              disabled
            ></el-input>
          </el-form-item>
          <el-form-item
            label="用户名"
            :label-width="formLabelWidth"
            class="from-item"
          >
            <el-input
              v-model="form.user_name"
              autocomplete="off"
              disabled
            ></el-input>
          </el-form-item>


          <el-form-item
            label="支付宝手机号"
            :label-width="formLabelWidth"
            class="from-item"
          >
            <el-input
              v-model="form.alipay_account"
              autocomplete="off"
            ></el-input>
          </el-form-item>

          <el-form-item
            label="提现总金额"
            :label-width="formLabelWidth"
            class="from-item"
          >
            <el-input
              v-model="form.withdraw_money"
              autocomplete="off"
              disabled
            ></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取消</el-button>
          <el-button type="primary" @click="queding">确定</el-button>
        </div>
      </el-dialog>
    </div>
    <!-- 分页 -->
    <div class="paging">
      <el-pagination
        @current-change="handleCurrentChange"
        :current-page.sync="currentPage"
        :page-size="pageNum"
        layout="prev, pager, next, jumper"
        :total="drugList"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
import http from '../api';
export default {
  data() {
    return {
      filterText: '',
      tableData: [],
      currentPage: 1,
      pageNum: 6,
      drugList: 0,
      dialogFormVisible: false,
      form: {
        user_id: '',
        user_name: '',
        withdraw_money: '',
        open_id: '',
        pay_password: '',
        alipay_account: '',
      },
      formLabelWidth: '120px',
      // 图片上传
      imageUrl: '',
    };
  },
  computed: {},
  mounted() {
    let nowPage = parseInt(this.currentPage);
    console.log(this.currentPage);
    this.getData();
  },
  methods: {
    //修改信息方法
    queding() {
      //支付密码
      let reg1 = /^[0-9]{6}$/;
      //手机号
      let reg2 = /^1[3|4|5|7|8][0-9]{9}$/;
      if (!reg1.test(this.form.pay_password)) {
        alert('请输入六位数字');
      } else if (!reg2.test(this.form.alipay_account)) {
        alert('请输入正确的手机号');
      } else {
        this.dialogFormVisible = false;
        this.form.pages = this.currentPage;
        this.form.pageSize = this.pageNum;
        this.form.inquire = this.filterText;
        http.userSafetyChange(this.form).then((r) => {
          console.log(r);
          this.tableData = r.data.data;
        });
      }
    },

    textNone(e) {
      console.log(e);
      this.getData();
    },
    textNone1(e) {
      if (e.target.value == '') {
        this.currentPage = 1;
        this.getData();
      }
    },
    modify(row) {
      // this.$refs.modifyinfo.open(row);
      //返回当前对象
      console.log(row);
      this.form.user_id = row.user_id;
      this.form.user_name = row.user_name;
      this.form.withdraw_money = row.safetyInfo.withdraw_money;
      this.form.open_id = row.open_id;
      this.form.pay_password = row.safetyInfo.pay_password;
      this.form.alipay_account = row.safetyInfo.alipay_account;
      this.imageUrl = row.user_icon;
      this.dialogFormVisible = true;
    },
    sousuo() {
      console.log(1111);
      this.getData();
    },
    //获取数据
    getData() {
      http
        .userBaselData({
          params: {
            pages: this.currentPage,
            pageSize: 6,
            inquire: this.filterText,
          },
        })
        .then((r) => {
          console.log(r);
          this.drugList = r.data.counts;
          this.tableData = r.data.data;
        });
    },
    handleCurrentChange(val) {
      this.nowPage = val;
      this.getData();
    },
  },
};
</script>
<style scoped>
.table-content {
  margin-top: 50px;
}
.section1-1 {
  width: 190px;
  height: 40px;
  border: 1px solid gainsboro;
  display: flex;
  justify-content: center;
  background-color: white;
  align-items: center;
}
.input1 {
  width: 150px;
  height: 30px;
  border: none;
  margin-left: 10px;
  outline: none;
}
.paging {
  margin-top: 30px;
  margin-left: 30%;
 position: absolute;
  left: 190px;
  bottom: 60px;
}

.el-pagination >>> .el-pagination__jump {
  font-size: 17px;
}
.el-pagination >>> .el-icon {
  font-size: 17px;
}
.el-pagination >>> .number {
  font-size: 17px;
  width: 60px;
}

/* 模态框css */
.touxiangdiv {
  height: 260px;
}
.touxiang {
  position: relative;
  top: 5%;
  left: 35%;
  width: 150px;
  height: 150px;
  border-radius: 50%;
  background-color: rgb(235, 235, 235);
  /* background: url(../../static/img/02.jpg)no-repeat 4px 5px; */
}
/* -----------图片上传----------- */
.touxiang i {
  position: relative;
  top: -10px;
  left: -15px;
}
.touxiang >>> .el-icon-camera-solid {
  font-size: 45px;
  color: #8d8585;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
  /* border: 1px dashed #d9d9d9; */
}
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
.from-item {
  position: relative;
  left: -5%;
}
.total-box {
  background-color: white;
  padding-top: 30px;
  margin-top: 10px;
  height: 600px;
}
</style>